<?php
declare (strict_types=1);

namespace app\controller\admin;

use app\common\controller\BaseController;
use app\model\admin\Member as memberModel;
use think\App;
use \Throwable;

class Member extends BaseController
{
    protected $model;

    public function __construct(App $app, memberModel $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * 列表查询
     * @return array
     */
    public function query()
    {
        $where = [];
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 20);
        $order = null;
        $fields = 'member_id,member_id assistant_name,nickname,gender,balance,headimg,role,status,identify,create_time';
        return $this->model->getList($where, $fields, $order, $page, $pageSize);
    }

    /**
     * @return array
     * 开通助教
     */
    public function openAssistant()
    {
        try {
            $type = input('type', 1);
            $type == 1 && $scene = 'bind';
            $type == 1 || $scene = 'create_assistant';
            validate(\app\validate\admin\Member::class)
                ->scene($scene)
                ->check($this->params);
            $this->params['member_id'] = $this->memberId;
            return $this->model->openAssistant($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }
}
